package com.wn.model;

import lombok.Data;

import java.util.Objects;

/**
 * @author yellow Docter
 * @date 2022 -05-12
 * @desc
 */
@Data
public class R {

    // 数据
    private Object data;

    // 信息
    private String msg;

    // 状态码
    private Integer code;

    public static R OK(){
        R result = new R();
        result.setMsg("操作成功");
        result.setCode(Constants.SUCCESS_CODE);
        return result;
    }

    /**
     * 成功直接传入一个数据
     * @param obj
     * @return
     */
    public static R OK(Object obj){
        R result = new R();
        result.setMsg("操作成功");
        result.setCode(Constants.SUCCESS_CODE);
        result.setData(obj);
        return result;
    }

    public static R OK(String msg){
        R result = new R();
        result.setMsg(msg);
        result.setCode(Constants.SUCCESS_CODE);
        return result;
    }

    public static R ERROR() {
        R result = new R();
        result.setMsg("操作失败");
        result.setCode(Constants.ERROR_CODE);
        return result;
    }

    public static R ERROR(String msg) {
        R result = new R();
        result.setMsg(msg);
        result.setCode(Constants.ERROR_CODE);
        return result;
    }
}
